/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sharepoint3;

import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;

/**
 *
 * @author Thyago
 */
public class Manager {
    public static String xmlToString(Document docToString) {
    String returnString = "\n-------------- XML START --------------\n";
    try {
        //create string from xml tree
        //Output the XML
        //set up a transformer
        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer trans;
        trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        StringWriter sw = new StringWriter();
        StreamResult streamResult = new StreamResult(sw);
        DOMSource source = new DOMSource(docToString);
        trans.transform(source, streamResult);
        String xmlString = sw.toString();
        //print the XML
        returnString = returnString + xmlString;
    } catch (TransformerException ex) {
        Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex);
    }
    returnString = returnString + "-------------- XML END --------------";
    return returnString;
}
}
